package com.icode.core.dto.user;

import com.icode.core.model.user.Customer;
import com.icode.core.model.user.User;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.constraints.Pattern;


/**
 * Created with IntelliJ IDEA.
 * User: sunk
 * Date: 14-12-26
 * Time: 上午11:16
 * To change this template use File | Settings | File Templates.
 */
public class UserDTO {
    @Pattern(regexp = "^\\d{11}$", message = "手机号码不正确!")
    private String username;

    @Length(min = 6, max = 6, message = "请输入6位密码!")
    private String password;

    @NotEmpty(message = "请输入6位密码!")
    private String rePassword;

    private boolean isAgree;

    @NotEmpty(message = "")
    private String validationNum;

    @NotEmpty(message = "请输入验证码")
    private String verify;

    public UserDTO() {
    }

    public UserDTO(String username){
        this.username = username;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRePassword() {
        return rePassword;
    }

    public void setRePassword(String rePassword) {
        this.rePassword = rePassword;
    }

    public boolean isAgree() {
        return isAgree;
    }

    public void setAgree(boolean agree) {
        isAgree = agree;
    }

    public void setValidationNum(String validationNum) {
        this.validationNum = validationNum;
    }

    public String getVerify() {
        return verify;
    }

    public void setVerify(String verify) {
        this.verify = verify;
    }

    public String getValidationNum() {
        return validationNum;
    }

    public Customer toRegister() {
        return new Customer(this.username, this.password, "true");
    }

    public static UserDTO toDTO(User user){
        String username = user.getUsername();
        UserDTO userDTO = new UserDTO(username);
        return userDTO;
    }

}
